# 自定义过滤器my_filter
# from manager import app
from functools import wraps

# @app.template_filter("my_filter")
from flask import current_app
from flask import g
from flask import session


# def my_filter(index):
#     if index == 1:
#         return "first"
#     elif index == 2:
#         return "second"
#     elif index == 3:
#         return "third"
#     else:
#         return ""


def user_login_data(view_func):
    @wraps(view_func)
    def wrapper(*args, **kwargs):
        # 1.获取用户的登陆信息
        user_id = session.get("user_id")

        # 2.通过user_id取出用户对象
        user = None
        if user_id:
            try:
                from api.models import User
                user = User.query.get(user_id)
            except Exception as e:
                current_app.logger.error(e)
        g.user = user
        return view_func(*args, **kwargs)
    return wrapper
